<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/28
 * Time: 18:16
 */

namespace common\sources\read\valueservice;



use common\models\craftsman\ValueService;

class ValueServiceAccess implements IValueServiceAccess
{

	/**
	 * getType 返回页面检索类型
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/22
	 * @return array
	 */
	public function getType() {
		return [
			'return_type'    => '返款方式',//  1.平台返款，2.商家返款
			'interval_time'  => '发布间隔时间',
			'pub_timing'     => '定时发布时间',
			'end_timing'     => '定时结束时间',
			'chat_type'      => '聊天服务',//类型 1.默认聊天，2.无需买手聊天，3.自定义聊天关键字
			'exten_period'   => '延长买手购物周期',// 1.不延长，2.一个月，3.两个月，4.三个月
			'credit_card'    => '使用花呗信用卡',//截图  1.使用 2. 不使用
			'buy_sex'        => '买号性别',// 1. 默认 无 2.男号，3.女号
			'praise'         => '好评优化服务',//，1.默认好评，2.优质好评，3.自定义好评
			'prohibit'       => '禁止地区',
			'buy_age'        => '买号年龄区间',
			'up_rank'        => '提升任务排名',//1. 10花椒，2. 20花椒,3. 30花椒
			'reword_commise' => '佣金加赏',// 默认是不加
			'prio_audit'     => '优先审核',//，1.优先，0 不优先
			'expre_service'  => '快递服务',
			'free_shipping'  => '包邮',//  1.商品包邮，2.商品不包邮 必传
		];
	}

    public function getList($task_commod_id)
    {
        return ValueService::find()
                ->select("id,interval_time,interval_pepper,return_type,return_type_pepper,pub_timing,end_timing_pepper,pub_timing_pepper,end_timing,chat_type,chat_keys,chat_pepper,
                exten_period,extend_pepper,buy_sex,sex_pepper,praise,praise_keys,praise_pepper,prohibit,prohibit_pepper,buy_age,buy_age_pepper,credit_card_pepper,free_shipping,create_time,
                up_rank,up_rank_pepper,reword_commise,prio_audit,prio_audit_pepper,expre_service,weight,service_pepper")
                ->where(['task_commod_id' => $task_commod_id])
                ->asArray()
                ->one();
        // TODO: Implement getList() method.
    }


	/**
	 * getValueServiceSList 增值服务统计
	 * @param $data
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/22
	 * @return array
	 */
	public function getValueServiceSList($data) {
		$whereSql = $this->getValueServiceSListWhere($data);
		$query    = ValueService::find()->select('id,create_time,bus_id,task_commod_id,task_id')->where($whereSql);
		$list     = $query->offset(($data['page_num'] - 1) * $data['limit'])->limit($data['limit'])->orderBy("create_time desc ")->asArray()->all();
		return $list;
	}

	/**
	 * getValueServiceSListCount 总条数
	 * @param $data
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/22
	 * @return int|string
	 */
	public function getValueServiceSListCount($data) {
		$whereSql = $this->getValueServiceSListWhere($data);
		$query    = ValueService::find()->select('id')->where($whereSql);
		return $query->asArray()->count();
	}

	/**
	 * getValueServiceSListWhere 条件
	 * @param $data
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/22
	 * @return string
	 */
	private function getValueServiceSListWhere($data) {
		$whereSql = $data['type'] . ' >0';
		if (!empty($data[''])) {
			$whereSql .= ' and  create_time >=' . $data['begin_time'];
		}
		if (!empty($data[''])) {
			$whereSql .= ' and  create_time <=' . $data['end_time'];
		}
		return $whereSql;
	}
}